'''
判断正负之后把字符串通过ASCII求差转成数字
(ord(s[i])-ord('0'))
1. 判断正负， 正负号存在从第二位开始
2. 如果是负的， 最后加一个负号
3. 边界条件？
'''
# -*- coding:utf-8 -*-
class Solution:
    def StrToInt(self, s):
        # write code here
        if s is None:
            return 0
        length = len(s)
        if length ==0:
            return 0
        res = 0
        strat = 0
        flag = 1
        if s[0] == '+' or s[0] =='-':
            strat = 1
            if s[0] == '-':
                flag = -1
        for i in range(strat,length):
            if '0'<= s[i] <= '9':
                res = res*10+(ord(s[i])-ord('0'))
            else:
                return 0
        if flag == -1:
            res = -res
        return res
